var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

/**
 * [createFile description]
 * @param  {String}  sfilePath [fileName]
 * @param  {Boolean} isAppend  [isAppend]
 * @return {WriteStream}       [description]
 */
function createFile(sfilePath, isAppend) {
    // folder path
    var dir_name = path.dirname(sfilePath);
    // resolve full file path
    var ori_path = path.resolve(sfilePath);
    // resolve folder path
    var dir_path = path.resolve(dir_name);

    mkdirp.sync(dir_path);

    if (isAppend)
      return fs.createWriteStream(ori_path, {flags:'a+'});
    else
      return fs.createWriteStream(ori_path);
}

module.exports = createFile;